Writes (or removes) JavaScript actions to an output stream.
public static void WriteJavaScript(
stream sourceStream,
string password,
IList<PDFJavaScript> Script_,
stream destinationStream
)
public static void WriteJavaScript(
Stream^ sourceStream,
String^ password,
IList<PDFJavaScript>^ Script_,
Stream^ destinationStream
)
sourceStream
Stream containing the source PDF.
password
The password to use if sourceStream contains an encrypted PDF.
javaScript
List of WriteJavaScript
actions to be written. If null or the array is empty, the function deletes the JavaScript from the file.
destinationStream
Stream that will contain the output PDF.
If javaScript is not null and contains valid JavaScript actions, WriteJavaScript
will:
If the source PDF file contains JavaScript, those operations will be replaced by the actions from javaScript. To add JavaScript actions to the existing JavaScript actions from the source file, follow these steps:
WriteJavaScript
.If javaScript is null, WriteJavaScript
will remove any JavaScript from the file.
There are several variations of this function, which take the source from a disk file or a stream and write the output to a disk file or a stream.
The actions from javaScript will be sorted in ascending order by the PDFJavaScript.Name property. This means the order in which the JavaScript actions are written to the ourput and executed by the JavaScript interpreter is not necessarily the order in which you add them to the javaScript list. See PDFJavaScript.Name for more details.
The example below demonstrates the result of this sort. The example adds two actions named name2
and name1
. The write however, changes the order and writes them in the order name1
, name2
. So when you load the resulting PDF file in a viewer that supports JavaScript (eg: web browser), the messages are displayed in reverse order.
using Leadtools.WinForms;
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Controls;
using Leadtools.Drawing;
using Leadtools.ImageProcessing;
using Leadtools.Pdf;
using Leadtools.Svg;
public void TestWriteJavaScript_Stream_string_IList_Stream()
{
string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "leadtools.pdf"); ;
string dstFileName = Path.Combine(LEAD_VARS.ImagesDir, @"out.pdf");
List<PDFJavaScript> list = new List<PDFJavaScript>(2);
PDFJavaScript item;
item.Name = "name2";
item.Code = "app.alert(\"Hello 2\");";
list.Add(item);
item.Name = "name1";
item.Code = "app.alert(\"Hello 1\");";
list.Add(item);
using (FileStream srcStream = File.Open(srcFileName, FileMode.Open))
using (FileStream destStream = File.Create(dstFileName))
PDFFile.WriteJavaScript(srcStream, null, list, destStream);
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images";
}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document